<?php
session_start();
if (isset($_SESSION['admin_id'])) {
    $mes = "";
    if (isset($_SESSION['mes'])) {
        $mes = $_SESSION['mes'];
        $_SESSION['mes'] = "";
    }
    include ("../include/menu.php");
    include "../include/dbFunctions.php";
    include "../include/formFunctions.php";
    $id = $_SESSION['vid'] = $_GET['id'];
// Data from volunteer table
    $query1 = "SELECT * FROM volunteer WHERE volunteer_id = $id";
    $volunteer_array = executeSelectQuery($query1);
    $salutation = $volunteer_array[0]['volunteer_salutation'];
    $name = $volunteer_array[0]['volunteer_firstname'] . " " . $volunteer_array[0]['volunteer_surname'];
    $gender = $volunteer_array[0]['volunteer_gender'];
    $status = $volunteer_array[0]['volunteer_status'];
    $email = $volunteer_array[0]['volunteer_email'];
    $office = $volunteer_array[0]['volunteer_office'];
    $mobile = $volunteer_array[0]['volunteer_mobile'];
    $job = $volunteer_array[0]['volunteer_profession'];
    $exp = $volunteer_array[0]['volunteer_experience'];
    $ref = $volunteer_array[0]['volunteer_reference'];
    $cv = $volunteer_array[0]['volunteer_cv'];
    $sponsor_id = $volunteer_array[0]['sponsor_id'];
    $comment = $volunteer_array[0]['volunteer_comment'];
// Data from sponsor table
    if ($sponsor_id == null) {
        $sponsor = "Individual";
    } else {
        $query2 = "SELECT * FROM sponsor WHERE sponsor_id = $sponsor_id";
        $sponsor_array = executeSelectQuery($query2);
        $sponsor = $sponsor_array[0]['sponsor_name'];
    }
//Data from preferred educational level
    $msg = "";
    $query3 = "SELECT e.education_name
                FROM education e, education_preference p
                WHERE e.education_id = p.education_id
                AND p.volunteer_id = $id";
    $education_array = executeSelectQuery($query3);
    if ($education_array == null) {
        $msg = "No preference";
    }
//Data from preferred location
    $msgl = "";
    $query4 = "SELECT l.location_name
                FROM location l, location_preference p
                WHERE l.location_id = p.location_id
                AND p.volunteer_id = $id";
    $location_array = executeSelectQuery($query4);
    if ($location_array == null) {
        $msgl = "No preference";
    }
//Data from trainer & event table
    $query5 = "SELECT *
                FROM event e, trainer t
                WHERE e.event_id = t.event_id
                AND t.volunteer_id = $id
                AND t.trainer_status = 'confirmed'";
    $event_array = executeSelectQuery($query5);
    //start - end
    if ($event_array != null) {
        $query51 = "SELECT * FROM session WHERE event_id = " . $event_array[0]['event_id'];
        $session_array = executeSelectQuery($query51);
        $first = $last = $session_array[0]['session_date'];
        for ($i = 0; $i < count($session_array); $i++) {
            if ($session_array[$i]['session_date'] < $first) {
                $first = $session_array[$i]['session_date'];
            }
            if ($session_array[$i]['session_date'] > $last) {
                $last = $session_array[$i]['session_date'];
            }
        }
    }
    //
//Timeslot preference
    $query10 = "SELECT t.time_name,tp.volunteer_id
                    FROM time_preference tp, time t
                    WHERE t.time_id = tp.time_id
                    AND volunteer_id='" . $id . "'";
    $time_array = executeSelectQuery($query10);
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http//www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http//www.w3.org/1999/xhtml">
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
            <title>JA Scheduling</title>

            <script type="text/javascript" language="javascript" src="../media/js/jquery/jquery-1.6.1.min.js"></script>
            <script type="text/javascript" language="javascript" src="../media/js/jquery/dataTable.js"></script>

            <!--  CSS script -->
            <link rel="stylesheet" href="../media/css/screen.css" type="text/css" media="screen" title="default" />
            <link type="text/css" href="../media/css/dataTable.css" rel="stylesheet" />

            <!-- Manage table script -->
            <script type="text/javascript" charset="utf-8">
                $(document).ready(function() {
                    $('#admintable').dataTable( {
                        "sPaginationType": "full_numbers"
                    } );
                } );
            </script>
        </head>
        <body>
            <!-- DON'T TOUCH! Start page-top-outer -->
            <?php
            top_outer();
            ?>
            <!-- End page-top-outer -->

            <div class="clear">&nbsp;</div>

            <!--  start nav-outer-repeat................................................................................................. START -->
            <div class="nav-outer-repeat">
                <!--  start nav-outer -->
                <div class="nav-outer">

                    <!-- start nav-right -->
                    <?php
                    nav_right();
                    ?>
                    <!-- end nav-right -->


                    <!--  start nav -->
                    <div class="nav">
                        <div class="table">

                            <?php
                            navigation_volunteer();
                            ?>

                            <div class="clear"></div>
                        </div>
                        <div class="clear"></div>
                    </div>
                    <!--  start nav -->

                </div>
                <div class="clear"></div>
                <!--  start nav-outer -->
            </div>
            <!--  start nav-outer-repeat................................................... END -->

            <div class="clear"></div>

            <!-- start content-outer ........................................................................................................................START -->
            <div id="content-outer">
                <!-- start content -->
                <div id="content">

                    <!--  start page-heading --> <!--lyedit-->
                    <div id="page-heading">
                        <h1>View Volunteer</h1>
                    </div>
                    <!-- end page-heading -->
                    <table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
                        <tr>
                            <th rowspan="3" class="sized"><img src="../media/images/shared/side_shadowleft.jpg" width="20" height="300" alt="" /></th>
                            <th class="topleft"></th>
                            <td id="tbl-border-top">&nbsp;</td>
                            <th class="topright"></th>
                            <th rowspan="3" class="sized"><img src="../media/images/shared/side_shadowright.jpg" width="20" height="300" alt="" /></th>
                        </tr>
                        <tr>
                            <td id="tbl-border-left"></td>
                            <td>
                                <!--  start content-table-inner ...................................................................... START -->
                                <div id="content-table-inner">
                                    <h2></h2>
                                    <!--  start table-content  -->
                                    <div id="table-content">
                                        <!--  Can put table start from here within this div-->

                                        <div id="details_content">
                                            <!-- General information-->
                                            <b><font color = 'red'><?php echo $mes; ?></font></b><br/>
                                            <h3>Personal Information<a href="volunteerUpdateGeneral.php"><img src="../media/images/forms/edit-icon.png" width=15></img></a></h3></h3>
                                            <table border="0" cellpadding="0" cellspacing="0"  id="id-form">
                                                <tr>
                                                    <th valign="top">Name </th>
                                                    <td><?php echo $salutation . " " . $name ?></td>
                                                </tr>
                                                <tr>
                                                    <th valign="top">Gender</th>
                                                    <td><?php echo ucfirst($gender); ?></td>
                                                </tr>

                                                <tr>
                                                    <th valign="top">Office Phone</th>
                                                    <td><?php echo $office; ?></td>
                                                </tr>
                                                <tr>
                                                    <th valign="top">Mobile Phone</th>
                                                    <td><?php echo $mobile; ?></td>
                                                </tr>
                                                <tr>
                                                    <th valign="top">Organization</th>
                                                    <td><?php echo ucfirst($sponsor); ?></td>
                                                </tr>
                                                <tr>
                                                    <th valign="top">Profession</th>
                                                    <td><?php echo ucfirst($job); ?></td>
                                                </tr>
                                                <tr>
                                                    <th valign="top">Experience</th>
                                                    <td><?php echo ucfirst($exp); ?></td>
                                                </tr>
                                                <tr>
                                                    <th valign="top">Reference</th>
                                                    <td><?php echo ucfirst($ref); ?></td>
                                                </tr>
                                                <tr>
                                                    <th valign="top">Resumé</th>
                                                    <td><?php echo "<a href= '../upload/cv/$cv'>" . ucfirst($cv) . "</a>"; ?></td>
                                                </tr>
                                                <tr>
                                                    <th valign="top">Comment</th>
                                                    <td><table width="500">
                                                            <tr><td><?php echo ($comment); ?></td></tr>
                                                        </table>
                                                    </td>
                                                </tr>
                                            </table>
                                            <br/>
                                            <!--Account Information-->
                                            <h3>Account Information<a href="volunteerUpdateAccount.php"><img src="../media/images/forms/edit-icon.png" width=15></img></a></h3></h3>
                                            <table border="0" cellpadding="0" cellspacing="0"  id="id-form">
                                                <tr>
                                                    <th valign="top">Email</th>
                                                    <td><a href="mailto<?php echo $email; ?>"><?php echo ucfirst($email); ?></a></td>
                                                </tr>
                                                <tr>
                                                    <th valign="top">Password</th>
                                                    <td>*******</td>
                                                </tr>
                                                <tr>
                                                    <th valign="top">Status</th>
                                                    <td><?php echo getVolunteerMainStatus($status); ?></td>
                                                </tr>
                                            </table>
                                            <br/>
                                            <!--Preference-->
                                            <h3>Preference<a href="volunteerUpdatePreference.php?id=<?php echo $id ?>"><img src="../media/images/forms/edit-icon.png" width=15></img></a></h3></h3>
                                            <table border="0" cellpadding="0" cellspacing="0"  id="id-form">
                                                <tr>
                                                    <th valign="top">Preferred<br/>Educational Level</th>
                                                    <td>
                                                        <?php
                                                        echo $msg;
                                                        for ($i = 0; $i < count($education_array); $i++) {
                                                            $education = ucwords($education_array[$i]['education_name']);
                                                            echo "- " . $education . "<br/>";
                                                        }
                                                        ?></td>
                                                </tr>
                                                <tr>
                                                    <th valign="top">Preferred Location<INPUT type="button" value="" class="form-help" onClick="window.open('../include/singaporeArea.php','mywindow','width=520,height=340')"></th>
                                                    <td>
                                                        <?php
                                                        echo $msgl;
                                                        for ($i = 0; $i < count($location_array); $i++) {
                                                            $location = ucwords($location_array[$i]['location_name']);
                                                            echo "- " . $location . "<br/>";
                                                        }
                                                        ?></td>
                                                </tr>
                                                <tr>
                                                    <th valign="top">Preferred Day</th>
                                                    <td>
                                                        <?php
                                                        for ($i = 0; $i < count($time_array); $i++) {
                                                            echo "- " . $time_array[$i]['time_name'] . "<br/>";
                                                        }
                                                        ?>
                                                    </td>
                                                </tr>
                                            </table>
                                            <br/>
                                            <!--Menu Edit andn Delete-->
                                            <table>
                                                <tr>
                                                    <td>
                                                        <form action="">
                                                            <input type="button" class="form-back" value="" onClick="javascripthistory.go(-1)"/>
                                                        </form>
                                                    </td>
                                                    <td>
                                                        <form method="GET" action= 'action/volunteerDelete.php' id="submitform">
                                                            <input type="hidden" name="id" value=<?php echo $id; ?>></input>
                                                            <input type="Submit" class="form-delete" name="Delete" value="&nbsp" onClick="if (confirm('This volunteer will be deleted permanently. Do you wish to continue?')) commentDelete(1); return false"/>
                                                        </form>
                                                    </td>
                                                </tr>
                                            </table>
                                            <!--Volunteer Event-->
                                            <br/>
                                            <h3>Volunteer's Event</h3>
                                            <table cellpadding="0" cellspacing="0" border="0" class="display" id="admintable">
                                                <thead>
                                                    <tr>
                                                        <th>No.</th>
                                                        <th>Event</th>
                                                        <th>Start date</th>
                                                        <th>End date</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    <?php
                                                    for ($i = 0; $i < count($event_array); $i++) {
                                                        $no = $i + 1;
                                                        $event_id = $event_array[$i]['event_id'];
                                                        $event = $event_array[$i]['event_name'];

                                                        echo "<tr>";
                                                        echo "<td>$no</td>";
                                                        echo "<td><a href='../event/eventView.php?id=$event_id'>$event</a></td>";
                                                        echo "<td>$first</td>";
                                                        echo "<td>$last</td>";
                                                        echo "</tr>";
                                                    }
                                                    ?>
                                                </tbody>
                                            </table>

                                        </div>

                                        <!--  end table-content here -->
                                    </div>
                                    <div class="clear"></div>
                                </div>
                                <!--  end content-table-inner ............................................END  -->
                            </td>
                            <td id="tbl-border-right"></td>
                        </tr>
                        <tr>
                            <th class="sized bottomleft"></th>
                            <td id="tbl-border-bottom">&nbsp;</td>
                            <th class="sized bottomright"></th>
                        </tr>
                    </table>
                    <div class="clear">&nbsp;</div>

                </div>
                <!--  end content -->
                <div class="clear">&nbsp;</div>
            </div>
            <!--  end content-outer........................................................END -->
    <?php
    footer();
    ?>

        </body>
    </html>
    <?php
} else {
    header("Location ../include/login.html");
}
?>